import { getCheckFlowNodeDetailById } from '@/api/basic'
import { ref } from 'vue'

/**
 * 审批流节点详情服务
 */
export default function () {
  const getCheckFlowNodeDetailLoading = ref(false)
  const checkFlowNodeDetail = ref<BaseInfoAPIResponse.CheckFlowNodeDetail>({
    approvalOrRejectRoleId: '',
    approvalOrRejectUserId: '',
    gmtCreate: '',
    gmtUpdate: '',
    id: '',
    nodeName: '',
    empIds: [],
  })

  const getCheckFlowNodeDetail = async (nodeId: string) => {
    try {
      getCheckFlowNodeDetailLoading.value = true
      const res = await getCheckFlowNodeDetailById(nodeId)
      getCheckFlowNodeDetailLoading.value = false
      if (res.data.code === 20000) {
        checkFlowNodeDetail.value = res.data.data.row
        return ''
      }

      return res.data.message
    } catch (error) {
      getCheckFlowNodeDetailLoading.value = false
      return '获取节点详情失败，请稍后重试'
    }
  }

  return {
    checkFlowNodeDetail,
    getCheckFlowNodeDetailLoading,
    getCheckFlowNodeDetail,
  }
}
